package com.cloud.controller;

import com.cloud.entity.Goods;
import com.cloud.entity.GoodsType;
import com.cloud.entity.PageInfo;
import com.cloud.service.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author .
 * created in 2020/1/14 22:51
 */

@RestController
@RequestMapping(value = "/goods")
public class GoodsController {

    private Logger logger = LoggerFactory.getLogger(GoodsController.class);

    private GoodsService goodsServiceImpl;

    public GoodsController(GoodsService goodsServiceImpl) {
        this.goodsServiceImpl = goodsServiceImpl;
    }

    @PostMapping(value = "/addGoodsType")
    public int addGoodsType(GoodsType type) {
        return goodsServiceImpl.addGoodsType(type);
    }

    @PostMapping(value = "/delGoodsType/{id}")
    public int delGoodsType(@PathVariable("id") String id) {
        return goodsServiceImpl.delGoodsType(id);
    }

    @PostMapping(value = "/updateGoodsType")
    public int updateGoodsType(GoodsType type) {
        return goodsServiceImpl.updateGoodsType(type);
    }

    @GetMapping(value = "/findById/{id}")
    public GoodsType findById(@PathVariable("id") String id) {
        return goodsServiceImpl.findById(id);
    }

    @GetMapping(value = "/findByName")
    public GoodsType findByName(@RequestParam("name") String name) {
        return goodsServiceImpl.findByName(name);
    }

    @GetMapping(value = "/findAllByPage")
    public PageInfo<GoodsType> findAllByPage(PageInfo<GoodsType> info,
                                             @RequestParam(value = "name", defaultValue = "") String name) {
        return goodsServiceImpl.findAllByPage(info, name);
    }

    @GetMapping(value = "/getEcharts")
    public Map<String, Object> getGoodsTypeEcharts() {
        return goodsServiceImpl.getGoodsTypeEcharts();
    }

    @GetMapping(value = "/findAllType")
    public List<GoodsType> findAllType() {
        return goodsServiceImpl.findAllType();
    }

    @PostMapping(value = "/addGoods")
    public int addGoods(Goods goods) {
        return goodsServiceImpl.addGoods(goods);
    }

    @PostMapping(value = "/delGoods/{id}")
    public int delGoods(@PathVariable("id") int id) {
        return goodsServiceImpl.delGoods(id);
    }

    @PostMapping(value = "/updateGoods")
    public int updateGoods(Goods goods) {
        return goodsServiceImpl.updateGoods(goods);
    }

    @GetMapping(value = "/findGoodsByPage")
    public PageInfo<Goods> findGoodsByPage(PageInfo<Goods> info,
                                       @RequestParam(value = "type", defaultValue = "") String type,
                                           @RequestParam(value = "name", defaultValue = "") String name) {
        return goodsServiceImpl.findGoodsByPage(info, type, name);
    }

    @GetMapping(value = "/findGoodsById/{id}")
    public Goods findGoodsById(@PathVariable("id") int id) {
        return goodsServiceImpl.findGoodsById(id);
    }

    @GetMapping(value = "/findAllGoodsByName")
    public List<String> findAllGoodsByName(@RequestParam(value = "name", defaultValue = "") String name) {
        return goodsServiceImpl.findAllGoodsByName(name);
    }

}
